

const TOKEN_KEY = 'USER_TOKEN_KEY'
const USERID_KEY = 'USERID_KEY'
const USER_INFO_KEY = 'USER_INFO_KEY'
// 存
export const setToken = (token) => {
  localStorage.setItem(TOKEN_KEY,token)
}


//取
export const getToken = () => {
  return localStorage.getItem(TOKEN_KEY)
}

// 删除
export const removeToken = () => {
  localStorage.removeItem(TOKEN_KEY)
}


export const setUserId = (id) => {
  localStorage.setItem(USERID_KEY,id)
}
export const getUserId = () => {
  const obj = JSON.parse(localStorage.getItem(USER_INFO_KEY))
  if (obj == null) {
    return null;
  }
  return obj.id
}

export const getUserRole = () => {
  const obj = JSON.parse(localStorage.getItem(USER_INFO_KEY))
  if (obj == null) {
    return null;
  }
  return obj.accountRole
}

export const removeUserId = () => {
  localStorage.removeItem(USERID_KEY)
}

export const setUserInfo = (userInfo) => {
  const obj = JSON.stringify(userInfo)
  localStorage.setItem(USER_INFO_KEY,obj)
}

export const removeUserInfo = () => {
  localStorage.removeItem(USER_INFO_KEY)
}
